package com.activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.util.R;
import com.util.okhttputils.OkHttpUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnItemClick;


/**
 * Created by Administrator on 2016/3/16.
 */
public class MainActivity extends BaseActivity {
    @Bind(R.id.lv_frameWork_main)
    ListView lv_framework;
    private Intent it_okHttpActivity = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        initData();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (it_okHttpActivity != null) {
            OkHttpUtils.getInstance().cancelTag(it_okHttpActivity);
        }
    }

    @Override
    protected void initData() {
        super.initData();
        List<String> listContent = new ArrayList<>();
        listContent.add("图片压缩");
        listContent.add("注解式框架Butter Knife");
        listContent.add("多线程读取文件");
        listContent.add("RecyclerView");
        listContent.add("View滑动");
        listContent.add("自定义ToolBar");
        listContent.add("okHttp");
        listContent.add("流式布局");
        listContent.add("下拉菜单");
        listContent.add("9Patch图片");
        listContent.add("弹性滑动");
        listContent.add("滑动删除");
        listContent.add("下拉刷新上拉加载更多");
        listContent.add("自定义日历控件");
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_expandable_list_item_1, listContent);
        lv_framework.setAdapter(adapter);

    }

    @OnItemClick(R.id.lv_frameWork_main) //方法的参数跟回调方法的一样，而且可以写只需要的参数
    public void onLvFrameworkItemClick(AdapterView<?> parent, View view, int position, long id) {
        switch (position) {
            case 0:
                myStartActivity(ImageCompressActivity.class);
                break;
            case 1:
                myStartActivity(ButterKnifeActivity.class);
                break;
            case 2:
                myStartActivity(MultiThreadsActivity.class);
                break;
            case 3:
                myStartActivity(RecyclerViewActivity.class);
                break;
            case 4:
                myStartActivity(SlidingViewActivity.class);
                break;
            case 5:
                myStartActivity(CommonToolBarActivity.class);
                break;
            case 6:
                it_okHttpActivity = new Intent(MainActivity.this, OkHttpActivity.class);
                startActivity(it_okHttpActivity);
                break;
            case 7:
                myStartActivity(FlowLayoutActivity.class);
                break;
            case 8:
                myStartActivity(DropDownMenuActivity.class);
                break;
            case 9:
                myStartActivity(NinePatchActivity.class);
                break;
            case 10:
                myStartActivity(ElasticityScrollLayoutAcy.class);
                break;
            case 11:
                myStartActivity(SwipeItemLayoutAcy.class);
                break;
            case 12:
                myStartActivity(DropDownAndPullUpAcy.class);
                break;
            case 13:
                myStartActivity(DatePickerAcy.class);
                break;
        }
    }

    //    @OnItemClick(R.id.lv_frameWork_main) //效果跟上面的方法一样
//    public void onLvFrameworkItemClick(int position) {
//        ToastUtil.showBottomToast(lv_framework.getAdapter().getItem(position));
//    }
    private void myStartActivity(Class<?> cls) {
        Intent it = new Intent(MainActivity.this, cls);
        startActivity(it);
    }

    class CancelUpdateApkReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (it_okHttpActivity != null) {
                OkHttpUtils.getInstance().cancelTag(it_okHttpActivity);
            }
        }
    }

}